package com.lucky.back.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.lucky.back.pojo.dto.AnnouncementAddNewDTO;
import com.lucky.back.pojo.dto.AnnouncementUpdateDTO;
import com.lucky.back.pojo.dto.BannerAddNewDTO;
import com.lucky.back.pojo.vo.AnnouncementListItemVO;
import com.lucky.back.pojo.vo.AnnouncementStandardVO;
import com.lucky.back.pojo.vo.BannerListItemVO;
import com.lucky.back.service.IAnnouncementService;
import com.lucky.back.service.IBannerService;
import com.lucky.back.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Slf4j
@Api(tags = "06.公告管理模块")
@RestController
@RequestMapping("/announcement")
public class AnnouncementController {
    @Autowired
    IAnnouncementService announcementService;

    public AnnouncementController() {
        log.debug("创建控制器对象：AnnouncementController");
    }

    @ApiOperation("添加公告")
    @ApiOperationSupport(order = 100)
    @PostMapping("/add-new")
    public JsonResult<Void> addNew(@Validated AnnouncementAddNewDTO announcementAddNewDTO) {
        log.debug("开始处理【添加公告】的请求，参数：{}", announcementAddNewDTO);
        log.debug("开始处理【添加公告】的请求，参数：{}", announcementAddNewDTO);
        announcementService.addNew(announcementAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除公告")
    @ApiOperationSupport(order = 200)
    @PostMapping("/{id:[0-9]+}/delete")
    public JsonResult<Void> delete(@PathVariable Long id) {
        log.debug("开始处理【删除公告】的请求，参数：{}", id);
        announcementService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("修改公告详情")
    @ApiOperationSupport(order = 300)
    @PostMapping("/{id:[0-9]+}/update")
    public JsonResult<Void> updateById(@PathVariable Long id, AnnouncementUpdateDTO announcementUpdateDTO) {
        log.debug("开始处理【修改公告册详情】的请求：id={}, announcementUpdateDTO={}", id, announcementUpdateDTO);
        announcementService.updateInfoById(id, announcementUpdateDTO);
        return JsonResult.ok();
    }

    @ApiOperation("根据id查询公告详情")
    @ApiOperationSupport(order = 400)
    @GetMapping("/{id:[0-9]+}")
    public JsonResult<AnnouncementStandardVO> getStandardById(@PathVariable Long id) {
        log.debug("开始处理【根据id查询公告详情】的请求：id={}", id);
        AnnouncementStandardVO album = announcementService.getStandardById(id);
        return JsonResult.ok(album);
    }

    @ApiOperation("查询公告列表")
    @ApiOperationSupport(order = 420)
    @GetMapping("")
    public JsonResult<List<AnnouncementListItemVO>> list() {
        log.debug("开始处理【查询相册列表】的请求");
        List<AnnouncementListItemVO> list = announcementService.list();
        return JsonResult.ok(list);
    }

}
